//-----------------------------------------------------------------------------
//  File          : apmfunc.c
//  Module        :
//  Description   : APM Functions.
//  Author        : Lewis
//  Notes         : N/A
//
// ============================================================================
// | Naming conventions                                                       |
// | ~~~~~~~~~~~~~~~~~~                                                       |
// |         Struct/Array : Leading s                                         |
// |             Constant : Leading K                                         |
// |      Global Variable : Leading g  (variable use outside one C file)      |
// |                                                                          |
// |   BYTE( 8 Bits) size : Leading b                                         |
// |   CHAR( 8 Bits) size : Leading c                                         |
// |   WORD(16 Bits) size : Leading w                                         |
// |  DWORD(32 Bits) size : Leading d                                         |
// |    int(32 Bits) size : Leading i                                         |
// | DDWORD(64 Bits) size : Leading dd                                        |
// |              Pointer : Leading p                                         |
// |                                                                          |
// |    Function argument : Leading a                                         |
// |       Local Variable : All lower case                                    |
// |                                                                          |
// | Examples:                                                                |
// |                Array : Leading s, (sb = arrary of byte, etc)             |
// |              Pointer : Leading p, (pb = pointer of byte, etc)            |
// ============================================================================
//
//  Date          Who         Action
//  ------------  ----------- -------------------------------------------------
//  01 Apr  2009  Lewis       Initial Version.
//-----------------------------------------------------------------------------
#include <string.h>
#include "midware.h"
#if (T800)
  #include "question.h"
#endif
#include "sysutil.h"
#include "kbdutil.h"
#include "apmconfig.h"
#include "apmtest.h"
#include "message.h"
#include "rmenu.h"
#include "apmfunc.h"

//-----------------------------------------------------------------------------
//      Defines
//-----------------------------------------------------------------------------
enum {
  APM_REBOOT = 0,
  APM_PWROFF,
  MAX_APMPWR_FUNC
};
//-----------------------------------------------------------------------------
//      Globals
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
//      Constants
//-----------------------------------------------------------------------------
char *KAPMFuncName[MAX_APM_FUNC] = {
  "APM Setup ",
  "APM Test ",
  "STIS "
};

static struct RMENUDAT KAPMPower[MAX_APMPWR_FUNC+1] = {
  {  0, "Reboot "             }, // extra space for current mark
  {  1, "PowerOff "           },
  { -1, ""                    },
};
//*****************************************************************************
//  Function        : Power
//  Description     : Confirm Power handle the Terminal.
//  Input           : N/A
//  Return          : N/A
//  Note            : N/A
//  Globals Changed : N/A
//*****************************************************************************
static void Power(void)
{
  int select;

#if (T800)
  select = RMenuSel(KAPMPower, KQuestionMark, "\x0E\x10\x1B\x06\x03POWER\x0F");
#else
  select = RMenuSel(KAPMPower, NULL, NULL);
#endif
  switch (select) {
    case APM_REBOOT:  // reboot
      ResetMW();
      break;
    case APM_PWROFF:
      PowerOffMW();
      break;
  }
}
//*****************************************************************************
//  Function        : APMFunc
//  Description     : APM function processor.
//  Input           : N/A
//  Return          : N/A
//  Note            : N/A
//  Globals Changed : N/A
//*****************************************************************************
void APMFunc(DWORD aID)
{
  switch (aID-APM_FUNC_START) {
    case APM_CONFIG:
      ApmConfig();
      break;
    case APM_TEST:
      ApmTest();
      break;
    case APM_STIS:
      STISConfig();
      break;
    case APM_PWR:
      Power();
      break;
  }
}
